<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>分店批发审核</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/res/layui-v2.5.6/css/layui.css" media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
    <script type="text/javascript" src="/res/js/jquery-3.4.1.min.js"></script>
    <script type="text/javascript" src="/res/js/util.js"></script>
    <script type="text/javascript" src="/ok-admin/js/permissionSetting.js"></script>
    <style>
        #myform{
            position: relative;
            top: 15px;
        }
    </style>
</head>
<body>

<form class="layui-form" action="" method="post" lay-filter="myform" id="myform">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">关键：</label>
            <div class="layui-input-inline">
                <input type="text" name="searchParam" id="searchParam" placeholder="请输入关键字" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-inline">
            <label class="layui-form-label">审核状态：</label>
            <div class="layui-input-inline">
                <select name="reviewState" id="reviewState" lay-filter="aihao">
                    <option value=""></option>
                    <option value="0">审核不通过</option>
                    <option value="1">等待审核</option>
                    <option value="2">财务审核通过</option>
                    <option value="3">审核通过</option>
                </select>
            </div>
        </div>

        <div class="layui-inline">
            <div class="layui-input-inline">
                <button type="button" class="layui-btn" lay-submit="" onclick="query()">搜索</button>
            </div>
        </div>

    </div>
</form>
<!--当前状态 根据状态定职位-->
<input type="hidden" name="status" id="status">
<table class="layui-hide" id="test" lay-filter="test"></table>

<script type="text/html" id="barDemo1">
    {{# if(returnUser()){ }}
        <button class="layui-btn layui-btn-danger layui-btn-xs layui-btn-disabled" disabled>审核</button>
    {{# }else{ }}
        {{# if(authorization("audit:managerAudit")){ }}
            {{# if(d.isva<40 ){ }}
                <a class="layui-btn layui-btn-danger layui-btn-xs" onclick="openAudit('40')" lay-event="audit" id="audit">审核</a>
            {{# }else{ }}
                <button class="layui-btn layui-btn-danger layui-btn-xs layui-btn-disabled" disabled>审核</button>
            {{# } }}
        {{# }else{ }}
            <button class="layui-btn layui-btn-danger layui-btn-xs layui-btn-disabled" disabled>审核</button>
        {{# } }}
    {{# } }}
</script>


<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">查看批发详情</a>
    <a class="layui-btn layui-btn-xs" lay-event="auditRecord">查询审核详情</a>
</script>

<script src="/res/layui-v2.5.6/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->

<script>
    var table = null;
    var perUser = null;
    var openIndex = null;
    layui.use(['table','layer'], function(){
        table = layui.table;
        var $ = layui.$;
        var layer = layui.layer;

        table.render({
            elem: '#test'
            ,url: '/immSell/shows'
            ,title: '分店批发审核'
            ,totalRow: true  //开启合计
            ,height: 'full-200', cellMinWidth: 80 //最大化适应
            ,height:600
            ,cols: [[
                {field:'sellId', title:'序号',type:'numbers', width:100, fixed: 'left',unresize: true, sort: 'true', totalRowText: '合计',align:"center"}
                ,{field:'sellCount', title:'销售数量', width:120, totalRow: true,align:"center"}
                ,{field:'sellMonty', title:'销售金额', width:120, totalRow: true,align:"center"}
                ,{field:'operator', title:'销售人', width:120,align:"center"}
                ,{field:'sellTime', title:'销售时间',align:"center"}
                ,{field:'remark', title:'备注', width:120,align:"center"}
                ,{field:'isva', title:'状态', width:180, templet: "#typeTpl",align:"center"}
                ,{fixed: 'right', title:'查询信息', toolbar: '#barDemo', width:250,align:"center"}
                ,{fixed: 'right', title:'操作', toolbar: '#barDemo1', width:150,align:"center"}
            ]]
            ,page: true
            ,id:'testReload'
            ,where:{//过滤流程
                status : "0,10"
            }
        });

        //头工具栏事件
        table.on('toolbar(test)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){

                //自定义头工具栏右侧图标 - 提示
                case 'LAYTABLE_TIPS':
                    layer.alert('这是工具栏右侧自定义的一个图标按钮');
                    break;
            };
        });

        //监听行工具事件
        table.on('tool(test)', function(obj){
            var data = obj.data;
            //console.log(obj)
            if(obj.event === 'edit'){
                var sid=data.sellId;
                var stype = data.sellType;
                console.info(sid);
                perUser = data;
                console.info(perUser);
                if(stype == 1){
                    onclose = layer.open({
                        type: 2,
                        skin: 'layui-layer-rim', //加上边框
                        area: ['100%', '100%'], //宽高
                        content: '/ok-admin/pages/ImmSell/wholesale.html?sellId='+sid,
                        end:function () {
                            // layer.msg("关闭ing");
                        }
                    });
                }
            }else if(obj.event === 'auditRecord'){
                console.info(data)
                var marketId = data.sellId;
                openIndex = layui.layer.open({
                    type: 2,
                    title: '审核详情',
                    area : ['80%' , '85%'],//弹出框大小
                    anim:1,
                    shadeClose:true,//点击也能遮罩层关闭
                    shift:1,//弹出框动画效果
                    skin: 'layui-layer-molv',//样式
                    shade: [0.8, '#393D49'] ,//显示遮罩
                    maxmin: true, //开启最大化最小化按钮
                    content: '/ok-admin/pages/audit/auditList.html?marketId='+marketId //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
                });
            }else if(obj.event === 'audit'){
                console.info(data)
                var id = data.sellId;
                //获取所点击审核的人的权限
                let status = $("#status").val();
                console.info($("#status").val());
                openIndex = layui.layer.open({
                    type: 2,
                    area: ['55%', '60%'], //宽高
                    title: '审核信息',
                    shift:1,//弹出框动画效果
                    skin: 'layui-layer-molv',//样式
                    shadeClose:true,//点击也能遮罩层关闭
                    shade: [0.8, '#393D49'] ,//显示遮罩
                    maxmin: true, //开启最大化最小化按钮
                    // content:  $("#popUpdateTest"),
                    content:`/ok-admin/pages/audit/auditForm.html?id=${id}&status=${status}&audit=wholesaleAudit`
                });
            }
        });
        //审核请求
        window.openAudit = function (status) {
            $("#status").val(status);
        }
    });

    /**
     * 关闭弹出层
     */
    function closeOpen(msg) {
        layer.close(openIndex);
        //语音播放
        playMessage(msg);
        layer.msg(msg, {time: 1000,icon:1}, function () {
            table.reload("testReload");//刷新表格
        })
    }
    /**
     * 错误提示 关闭弹出层
     */
    function errorCloseOpen(msg){
        layer.close(openIndex);
        //语音播放
        playMessage(msg);
        layer.msg(msg,{time:2000,icon:2},function(){
            table.reload("testReload");
            //window.location.reload(true);
        });
    }

    function query() {
        table.reload('testReload',{
            where:{
                searchParam:$("#searchParam").val()
            },
            page:{
                curr:1
            }
        })
    }

</script>
<script type="textml" id="typeTpl">
    {{# if(d.isva == 20){ }}
    <span class="layui-btn layui-btn-danger layui-btn-xs">待审核</span>
    {{#  } else if(d.isva == 40){ }}
    <span class="layui-btn layui-btn-warm layui-btn-xs">分公司总经理审核通过</span>
    {{#  } else if(d.isva == 41){ }}
    <span class="layui-btn layui-btn-danger layui-btn-xs">分公司总经理审核不通过</span>
    {{#  } }}
</script>
</body>
</html>